<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			.wrapper{
				width: 100%;
				height: 100px;
			}
			.bg{
				width: 1200px;
				height: 600px;
				position: relative;
				margin: 0 auto;
				float: none;
			}
			img{
				float: none;
				position: absolute;
				top: -200px;
				left: 100px;
			}
		</style>
	</head>
	<body>
		<div class="wrapper">
			<div class="bg">
				<img src="../img/system/icon/Exchange_img_max01.jpg"/>
			</div>
		</div>
		<?php
session_start();//重要
$username = !empty($_POST['username']) ? trim($_POST['username']) : '没有数据';
$password = !empty($_POST['password']) ? trim($_POST['password']) : '没有数据';
 
//链接数据库
$connect = mysqli_connect('localhost','root','123456','db_exchange');
if(!$connect) {
    echo '链接数据库失败';
    return;
}
mysqli_set_charset($connect , 'utf-8');
$sql = "select username,password from tb_login where username = '{$username}'";
$query = mysqli_query( $connect,$sql);
if(!$query) {
    echo '读取错误';
    return;
}
$row = mysqli_fetch_assoc($query);
    if($row['username'] == $username && $row['password'] == $password) {
        $_SESSION['username']  = $username;  //把username存到session中
        echo "<script>alert('登录成功！');window.location.href='../pages/index.php'</script>";
    } else {
        echo "<script>alert('用户名或密码错误，请重试');window.location.href='../pages/login.html'</script>";
    }
?>
	</body>
</html>
